package oj;

import java.util.Scanner;

public class Day36S{
    private static long num=1;
    private static long numArr[];
    public static void main(String[] args) {
        initArr();
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
            int n=sc.nextInt();
            String pre=sc.next();
            String post=sc.next();
            num=1;
            caculateTree(n,pre,post);
            System.out.println(num);
        }
    }

    private static void caculateTree(int n, String pre, String post) {
        int len=pre.length();
        if(len==1){
            return;
        }
        int count=0;
        pre=pre.substring(1);
        post=post.substring(0,len-1);
        while(!" ".equals(pre)){
            int index=post.indexOf(pre.charAt(0))+1;
            String newPre=pre.substring(0,index);
            String newPost=post.substring(0,index);
            count++;
            caculateTree(n,newPre,newPost);
        }
        num*=caculateCom(count,n);
    }

    private static long caculateCom(int sub, int n) {
        return numArr[n]/(numArr[n-sub]*numArr[sub]);
    }


    private static void initArr() {
        numArr=new long[21];
        numArr[0]=1;
        for (int i = 1; i < 21; i++) {
            numArr[i]=numArr[i-1]*i;
        }
    }
}
